unit cmdMUIDAddSelection;

interface

uses  classes, sysutils
    , toolsString
    , mapsXml
    , nativeXml
    , appMappldXmlNode
    , appMappldXmlCommand
    , appMappldTypes
    , appMappldXmlContext
    , appMappldLayer
    , appMappldXmlLayer
;

type
    {------------------------------ TCmdMUIDAddSelection }

    {***************************************************************************
    * TCmdMUIDAddSelection
    ***************************************************************************}
    TCmdMUIDAddSelection = class( TMappldXmlCommand )
protected
    procedure   internalProccess(); override;
    end;

implementation

{*******************************************************************************
* internalProccess
*******************************************************************************}
procedure TCmdMUIDAddSelection.internalProccess();
var
    nodes   : TMapXmlNodes;
    layer   : TMappldLayer;
    list    : TStringList;
    code    : string;
    objects : string;
    i       : integer;
    objId   : integer;
    muid    : int64;

begin
    nodes := nil;
    list  := nil;

    try
        nodes := TMapXmlNodes.Create();
        nodes.loadFromSubNodes( FxmlNode );

        code    := nodes.valueAsString( XML_A_code, '' );
        objects := nodes.valueAsString( XML_A_objects, '' );

        if ( ( code = '' ) or ( objects = '' ) ) then
        begin
            exit;
        end;

        layer := Fcontext.layersByCode[ code ];
        if ( layer = nil ) then
        begin
            exit;
        end;

        list := TStringList.Create();
        ParseParametersEx( objects, ',', list );

        for i := 0 to list.Count - 1 do
        begin
            muid := StrToInt64Def ( list[i], -1 );
            if ( muid = -1 ) then
            begin
                continue;
            end;

            objId := Fmappl.GetOkeyByMUID( layer.codeAsInteger, muid );
            if ( objId = -1 ) then
            begin
                continue;
            end;

            layer.selectedObjects[ objId ] := true;
        end;
    finally
        FreeAndNil( list );
        FreeAndNil( nodes );
    end;

end;

initialization

TMappldXmlCommand.registerCommandByCode( XML_CMD_MUIDAddSelection, TCmdMUIDAddSelection );

end.
